import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

  const routes = [
    {
      path:'/',
      name:'login',
      component: () => import('../components/login')
    },
  {
    path: '/',
    name: 'homepage',
    component: () => import('../views/homepage'),
    redirect:"/banner",
    children:[
      {
          path:'banner',
          component:() => import('../views/banner') 
      },
      {
        path:'main',
        component:() => import('../views/main') 
      },
      {
        path:'videodetail',
        component:() => import('../views/videodetail') 
      },
      {
        path:'morelist',
        component:() => import('../views/morelist') 
      },
      {
        path:'teacherclass',
        component:() => import('../views/teacherclass') 
      },
      {
        path:'usercenter',
        component: () => import('../views/usercenter')
      },
      {
        path:'search',
        component: () => import('../views/search')
      },
      {
        path:'arearanktotal',
        component: () => import('../views/arearanktotal')
      }
    ],
  },
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let Authorization = localStorage.getItem('sessionId')
  if(Authorization || to.fullPath=="/" ){
    next()
  }else{
    next()
      router.push({
        path:'/'
    })
  }
})


export default router
